﻿Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports Controladores
Imports BBDD

 _

Class modDatosPers
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        If Session("privUser") Is Nothing Or Integer.Parse(Session("privUser").ToString()) < 1 Then
            Response.Redirect("index.aspx")
        End If

        camponombre.Text = Consultas.getnombre(Session("DNIUser").ToString())
        camponombre.Enabled = True
        campoapellidos.Text = Consultas.getapellidos(Session("DNIUser").ToString())
        campoapellidos.Enabled = True
        campodireccion.Text = Consultas.getdireccion(Session("DNIUser").ToString())
        campodireccion.Enabled = True
        campoCP.Text = Consultas.getCP(Session("DNIUser").ToString()).ToString()
        campoCP.Enabled = True
        campolocalidad.Text = Consultas.getlocalidad(Session("DNIUser").ToString())
        campolocalidad.Enabled = True
        campopais.Text = Consultas.getpais(Session("DNIUser").ToString())
        campopais.Enabled = True
        campoemail.Text = Consultas.getemail(Session("DNIUser").ToString())
        campoemail.Enabled = True
        campoprovincia.Text = Consultas.getprovincia(Session("DNIUser").ToString())
        campoprovincia.Enabled = True
        campoTlf.Text = Consultas.gettelefono(Session("DNIUser").ToString()).ToString()
        campoTlf.Enabled = True
        campoPass.Text = Consultas.getcontrasena(Session("DNIUser").ToString())
        campoPass.Enabled = True
    End Sub 'Page_Load


    Protected Sub boton_modificarse_Click(ByVal sender As Object, ByVal e As EventArgs)

        If Me.camponombre Is Nothing Then
            Me.camponombre.Text = ""
        End If

        If Me.campoapellidos Is Nothing Then
            Me.campoapellidos.Text = ""
        End If

        If Me.campodireccion Is Nothing Then
            Me.campodireccion.Text = ""
        End If

        If Me.campoemail Is Nothing Then
            Me.campoemail.Text = ""
        End If

        If Me.campolocalidad Is Nothing Then
            Me.campolocalidad.Text = ""
        End If

        If Me.campopais Is Nothing Then
            Me.campopais.Text = ""
        End If

        If Me.campoTlf Is Nothing Then
            Me.campoTlf.Text = ""
        End If


        If Me.campoPass Is Nothing Then
            Me.campoPass.Text = ""
        End If

        If Me.campoCP Is Nothing Then
            Me.campoCP.Text = ""
        End If


        If Consultas.existeUsuario(Session("DNIUser").ToString()) Then
            Dim saldoUserActivo As Double = Consultas.getsaldo(Session("DNIUser").ToString())
            Dim ccUser As String = Consultas.getCCBanco(Session("DNIUser").ToString())
            Session("error") = controlador.modificarDatosUsuario(Session("DNIUser").ToString(), camponombre.Text, campoapellidos.Text, campoemail.Text, campodireccion.Text, Long.Parse(campoTlf.Text), campolocalidad.Text, campoprovincia.Text, campopais.Text, Integer.Parse(campoCP.Text), saldoUserActivo, campoPass.Text, ccUser, 0)
            If Session("error").ToString() = "" Then
                If Integer.Parse(Session("privUser").ToString()) > 1 Then
                    Response.Redirect("modUsuarioDNI.aspx")
                Else
                    Response.Redirect("index.aspx")
                End If
            Else
                controlador.CreateMessageAlert(Me, Session("error").ToString(), "Error en la operacion")
            End If 'Response.Redirect("error2.aspx");
        Else
            Session("error") = "No existe tal usuario para el DNI ingresado"
            controlador.CreateMessageAlert(Me, Session("error").ToString(), "Error en la operacion")
        End If 'Response.Redirect("error2.aspx");
    End Sub 'boton_modificarse_Click





    Protected Sub campodireccion_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        Me.campodireccion.Text = Me.campodireccion.Text
    End Sub 'campodireccion0_TextChanged

    Protected Sub camponombre_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        Me.camponombre.Text = Me.camponombre.Text
    End Sub 'camponombre0_TextChanged

    Protected Sub campoemail_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        Me.campoemail.Text = Me.campoemail.Text
    End Sub 'campoemail0_TextChanged

    Protected Sub campoTlf_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        Me.campoTlf.Text = Me.campoTlf.Text
    End Sub 'campoTlf0_TextChanged

    Protected Sub campolocalidad_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        Me.campolocalidad = Me.campolocalidad
    End Sub 'campolocalidad0_TextChanged

    Protected Sub campoprovincia_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        Me.campoprovincia.Text = Me.campoprovincia.Text
    End Sub 'campoprovincia0_TextChanged

    Protected Sub campopais_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        Me.campopais.Text = Me.campopais.Text
    End Sub 'campopais0_TextChanged

    Protected Sub campoCP_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        Me.campoCP.Text = Me.campoCP.Text
    End Sub 'campoCP0_TextChanged

    Protected Sub campoCP_TextChanged1(ByVal sender As Object, ByVal e As EventArgs)
        Me.campoCP.Text = Me.campoCP.Text
    End Sub 'campoCP0_TextChanged1

    Protected Sub campoPass_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        Me.campoPass.Text = Me.campoPass.Text
    End Sub 'campoPass0_TextChanged
End Class 'modDatosPers